package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.annotation.TingshuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserListenProcessApiController {

	@Autowired
	private UserListenProcessService userListenProcessService;


	@GetMapping("/getTrackBreakSecond/{trackId}")
	@TingshuLogin
	@Operation(summary = "获取声音断点秒数")
	@Parameters({
			@Parameter(name = "trackId", description = "声音id", required = true)
	})
	public Result getTrackBreakSecond(@PathVariable(value = "trackId") Long trackId) {
		BigDecimal breakSecond = userListenProcessService.getTrackBreakSecond(trackId);
		return Result.ok(breakSecond);
	}

	@PostMapping("/updateListenProcess")
	@TingshuLogin
	@Operation(summary = "更新MongoDB中声音播放进度")
	@Parameters({
			@Parameter(name = "userListenProcessVo", description = "用户播放声音信息Vo", required = true)
	})
	public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo) {

		userListenProcessService.updateListenProcess(userListenProcessVo);
		return Result.ok();
	}

	// Request URL: http://192.168.200.1:8500/api/user/userListenProcess/getLatelyTrack
	@GetMapping("/getLatelyTrack")
	@TingshuLogin
	@Operation(summary = "获取最近播放的声音")
	public Result getLatelyTrack() {

		HashMap<String, Object> result = userListenProcessService.getLatelyTrack();

		return Result.ok(result);

	}

}

